package com.zking.ssm.DYM.controller;

import com.zking.ssm.DYM.model.HotelRoomMoney;
import com.zking.ssm.DYM.service.IHotelRoomMoneyService;
import com.zking.ssm.util.JsonData;
import com.zking.ssm.util.PageBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description
 * @Author XXXXX
 * @Date 2021/01/19 22:36
 */
@Controller
@RequestMapping("/hotelRoomMoney")
public class HotelRoomMoneyController {
    @Autowired
    private IHotelRoomMoneyService hotelRoomMoneyService;

    @ModelAttribute
    public void init(Model model){
        System.out.println("init");
        HotelRoomMoney hotelRoomMoney = new HotelRoomMoney();
        model.addAttribute("hotelRoomMoney",hotelRoomMoney);
    }

    @RequestMapping(value = "/list")
    @ResponseBody
    public JsonData list(HotelRoomMoney hotelRoomMoney, PageBean pageBean){
        System.out.println("list");
        List<HotelRoomMoney> hotelRoomMoneyList = hotelRoomMoneyService.list(hotelRoomMoney, pageBean);
//        System.out.println("集合:"+hotelRoomMoneyList);
        JsonData jsonData = new JsonData();
        jsonData.setCode(0);
        jsonData.setPage(pageBean.getPage());
        jsonData.setRows(pageBean.getRows());
        jsonData.setTotal(pageBean.getTotal());
        jsonData.setMessage("查询成功");
        jsonData.setResult(hotelRoomMoneyList);
        return jsonData;
    }

    //修改房价
   @RequestMapping("/updateHotelRoomMoney/{id}")
    public String updateHotelRoomMoney(@PathVariable("id") Long id,Model model){
        model.addAttribute("hotelRoomMoney",hotelRoomMoneyService.selectByPrimaryKey(id));
        return "updateHotelRoomMoney";
    }
    @RequestMapping(value = "/update",method = RequestMethod.POST)
    public  String update(HotelRoomMoney hotelRoomMoney){
        hotelRoomMoneyService.updateByPrimaryKey(hotelRoomMoney);
        return "redirect:updateHotelRoomMoney";
    }
}
